lib.event.listen(window, 'load', function() {
	var createLabel = new lib.net.Rpc('createLabel');

	createLabel.listen(lib.net.Xhr.Event.COMPLETE, function(event, obj) {
		var labelID = obj;
		var div = document.createElement('DIV');

		var checkbox = document.createElement('INPUT');
		checkbox.type = 'checkbox';
		checkbox.name = 'labelIDs[]';
		checkbox.id = 'label' + labelID;
		checkbox.value = labelID;
		checkbox.checked = true;
		div.appendChild(checkbox);

		div.appendChild(document.createTextNode(' '));

		var labelNode = document.createElement('LABEL');
		labelNode.htmlFor = 'label' + labelID;
		labelNode.appendChild(document.createTextNode(label));
		div.appendChild(labelNode);

		document.getElementById('labels').insertBefore(div, document.getElementById('createLabel'));
	});
	createLabel.listen(lib.net.Xhr.Event.ERROR, function(event, error, msg) {
		alert("Could not create label: " + error);
	});

	var label = '';
	lib.event.listen(document.getElementById('createLabel'), 'click', function() {
		label = prompt('Enter the name of the label to create:');
		if (label != null && label != '') {
			createLabel.send(label);
		}
	});
});
